home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Devices & Hardware / Apple Desktop Bus / TabletGrabberƒ / TabletGrabber.p < prev    next >
Encoding:
Text File  |  1990-09-14  |  9.0 KB  |  256 lines  |  [TEXT/TPAS]

  1. PROGRAM    TabletGrabber;
  2. {$R TabletGrabber.Rsrc}
  3. {$U-}
  4.  
  5. USES
  6.     Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf;
  7.     
  8. TYPE
  9.  
  10.     OpData = record
  11.     TabltID : longint;
  12.     R0Data : array [0..9] of signedbyte;
  13.     MyFlags : byte;
  14.     R1Data : array [0..9] of signedbyte;
  15.     ResrvdByte : byte;
  16.     ResrvdPtr : ptr;
  17.     end;
  18.     
  19.     OpDataPtr = ^OpData;
  20.     
  21.     SysEnvRec      =       RECORD
  22.                 environsVersion:    INTEGER;
  23.                 machineType:           INTEGER;
  24.                 systemVersion:         INTEGER;
  25.                 processor:                INTEGER;
  26.                 hasFPU:                      BOOLEAN;
  27.                 hasColorQD:               BOOLEAN;
  28.                 keyBoardType:          INTEGER;
  29.                 atDrvrVersNum:         INTEGER;
  30.                 sysVRefNum:               INTEGER;
  31.                 END;
  32.  
  33.     SysEnvRecPtr = ^SysEnvRec;
  34.     
  35.     longintptr = ^longint;
  36.  
  37.  
  38. CONST
  39.       TextStatItem4 = 4;   {Item number of static text}
  40.       TextStatItem5 = 5;   {Item number of static text}
  41.       textItem = 3;        {item number for editable text item}
  42.       errorDialID = 257;
  43.       MainDialId = 258;
  44.       TabltAddrs = 4;
  45.       ID = $54424C54;
  46.  
  47. VAR
  48.     err : integer;
  49.              DialRect : Rect;
  50.              DialPtr : DialogPtr;
  51.              DialItemHit, DITLID,i : integer;
  52.              DITLHndl : handle;
  53.     GotADB,quit :boolean;
  54.     ResHell,theType : integer;   {gives the type of the item requested}
  55.     TextHdl1,TextHdl2 : handle;    {gives a handle to the item}
  56.     txtBox : Rect;    {gives the display rectangle of the item}
  57.     IDVal : packed array [0..4] of char;
  58.     OldX,OldY : array [0..1] of signedbyte;
  59.     MyBuffer,LongPtr : longintptr;
  60.     TheWorld : SysEnvRec;
  61.     EnvPtr : SysEnvRecPtr;
  62.     InfoBlk : ADBDataBlock;
  63.     DataAreaPtr : OpDataPtr;
  64.     theEvent : EventRecord;
  65.  
  66.         {------------------------------------------------------------------------------------}
  67.     
  68.   PROCEDURE debugger; INLINE $A9FF;
  69.  
  70.         {------------------------------------------------------------------------------------}
  71.  
  72.   FUNCTION SysEnvirons(versionRequested: INTEGER; VAR theWorld: SysEnvRec): OSErr;
  73.   
  74.   INLINE $205f,$301f, $A090, $3e80;
  75.  
  76.         {------------------------------------------------------------------------------------}
  77.  
  78.         PROCEDURE InitMac;
  79.  
  80.             BEGIN                       {InitMac}
  81.  
  82.    InitGraf (@thePort);          {the big five inits + 1}
  83.    InitFonts;
  84.    InitWindows;
  85.    TEInit;
  86.    InitDialogs (nil);
  87.    InitCursor;
  88.             END;                       {InitMac}
  89.  
  90.         {------------------------------------------------------------------------------------}
  91.  
  92. PROCEDURE DoError (ErStr : str255; err : longint);
  93.  
  94. CONST
  95.     TextStatItem = 2;
  96. VAR
  97.     NumStr : str255;
  98.     theTextHdl : handle;
  99.              DialPtr : DialogPtr;
  100.              DialItemHit, DITLID : integer;
  101.  
  102.     Begin
  103.         if err <> 0 then NumToString (err,NumStr)
  104.         else NumStr := '';
  105.         ErStr := Concat (ErStr,NumStr);
  106.         DITLID := 257;
  107.         DITLHndl := GetResource ('DITL', DITLID);
  108.         ResHell := ResError;
  109.         if ResHell = noerr then
  110.         begin
  111.             if DITLHndl <> nil then
  112.  
  113.             begin
  114.                 Hlock (DITLHndl);
  115.  
  116.                 DialPtr := GetNewDialog (257,nil,WindowPtr(-1));
  117.                 If DialPtr <> nil then
  118.                 begin
  119.                     GetDItem (DialPtr, TextStatItem, theType, theTextHdl, txtBox);
  120.                     If theTextHdl <> nil then
  121.                     begin
  122.      
  123.                         SetPort (DialPtr);
  124.  
  125.                         SetIText (theTextHdl, ErStr);
  126.                            repeat
  127.                             ModalDialog (nil, DialItemHit);
  128.                         until DialItemHit <> 0;
  129.                         Case DialItemHit of  {1 = OK btn, 2 = message}
  130.                         1,2 : CloseDialog (DialPtr);
  131.                                 
  132.                           end; {case}
  133.                     end;
  134.                 end;
  135.             end;
  136.         end;
  137.         If DITLHndl <> nil then HUnLock (DITLHndl);
  138.      end;
  139.  
  140.         {------------------------------------------------------------------------------------}
  141.  
  142. PROCEDURE ChangeIt (FirstOne, SecondOne:integer);
  143.  
  144. VAR
  145.     FirstOneTxt,SecondOneTxt : str255;
  146.     
  147. begin
  148.     NumToString (longint(FirstOne), FirstOneTxt);
  149.     NumToString (longint(SecondOne), SecondOneTxt);
  150.     SetIText (TextHdl1, FirstOneTxt);
  151.     SetIText (TextHdl2, SecondOneTxt);
  152. end;
  153.     
  154.         {------------------------------------------------------------------------------------}
  155.  
  156.     
  157.     begin {main DudeFace}
  158.       
  159.         initmac;
  160.         quit := false;
  161.         OldX[0] := 0;
  162.         OldX[1] := 0;
  163.         OldY[0] := 0;
  164.         OldY[1] := 0;
  165.         gotADB := false; {assume no ADB, and just exit if none}
  166.         err:= SysEnvirons (1,TheWorld);
  167.         if err = noerr then
  168.         begin
  169.             case theworld.machineType of
  170.             0,1,2 : begin
  171.                         gotADB := false;
  172.                         DoError ('Yes, we have no ADB today.',0);
  173.                         DoError ('Press the mouse button to exit.', 0);
  174.                         repeat until button;
  175.                 end;
  176.             Otherwise gotADB := True;
  177.             end; {case}
  178.         end
  179.         else
  180.         begin
  181.             DoError ('SysEnvirons error = ',err);
  182.             DoError ('Please press the mouse button to exit',0);
  183.             repeat until button;
  184.         end;
  185.             if GotADB then
  186.             begin
  187.                 err := GetADBInfo (InfoBlk,TabltAddrs);
  188.                 if err = noerr then
  189.                 begin
  190.                     if infoBlk.dbDataAreaAddr <> nil then
  191.                     begin
  192.                         DataAreaPtr :=  OpDataPtr(infoBlk.dbDataAreaAddr);
  193.                         if DataAreaPtr^.TabltID = ID then
  194.                         begin
  195.                             DITLID := MainDialId;
  196.                             DITLHndl := GetResource ('DITL', DITLID);
  197.                             ResHell := ResError;
  198.                             if ResHell = noerr then
  199.                             begin
  200.                                 if DITLHndl <> nil then
  201.                                 begin
  202.                                     Hlock (DITLHndl);
  203.                                     SetRect(DialRect,310,200,screenbits.bounds.right - 210,
  204.                                             screenbits.bounds.bottom - 100);            
  205.                                        DialPtr := GetNewDialog (MainDialId,nil,WindowPtr(-1));
  206.                                     If DialPtr <> nil then
  207.                                     begin
  208.                                         SetPort (DialPtr);
  209.                                         GetDItem (DialPtr, TextStatItem4, theType, TextHdl1, txtBox);
  210.                                         If TextHdl1 <> nil then
  211.                                         begin
  212.                                             GetDItem (DialPtr, TextStatItem5, theType, TextHdl2, txtBox);
  213.                                             If TextHdl2 <> nil then repeat
  214.                                             begin
  215.                                                 if (OldX[0] <> DataAreaPtr^.R0Data[3]) or
  216.                                                    (OldX[1] <> DataAreaPtr^.R0Data[4]) or
  217.                                                    (OldY[0] <> DataAreaPtr^.R0Data[5]) or
  218.                                                    (OldY[1] <> DataAreaPtr^.R0Data[6]) then
  219.                                                 begin
  220.                                                     OldX[0] := DataAreaPtr^.R0Data[3];
  221.                                                     OldX[1] := DataAreaPtr^.R0Data[4];
  222.                                                     OldY[0] := DataAreaPtr^.R0Data[5];
  223.                                                     OldY[1] := DataAreaPtr^.R0Data[6];
  224.                                                     ChangeIt (integer(OldX), integer(OldY));
  225.                                                 end;
  226.                                                 if GetNextEvent (EveryEvent, theEvent) then
  227.                                                 begin
  228.                                                     if IsDialogEvent (theEvent) then
  229.                                                     begin
  230.                                                         if DialogSelect (theEvent, DialPtr, DialItemHit) then
  231.                                                         case DialItemHit of
  232.                                                         1 : quit := true;
  233.                                                         end {case}
  234.                                                     end;
  235.                                                 end;
  236.                                             end;
  237.                                             until quit;
  238.                                         end;
  239.                                     end
  240.                                     else DoError ('Dialog Pointer is nil',0);
  241.                                 end
  242.                                 else DoError ('DITL Handle is nil',0);
  243.                             end
  244.                             else DoError ('Resource Error (DITL)',ResHell);
  245.                         end
  246.                         else DoError ('Can''t find ''TBLT'' ID',0);
  247.                     end
  248.                     else DoError ('Can''t find tablet data area',0);
  249.                 end
  250.                 else begin
  251.                         if err = -1 then DoError ('No Tablet Driver installed',0)
  252.                         else DoError ('GetADBInfo Error',err);
  253.                      end;
  254.             end
  255.             else DoError ('Yes, we have no ADB today',0);
  256.         end.